﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Model;
using Dal;
using Microsoft.EntityFrameworkCore;
using Dal.Iterfease;

namespace xiaomiApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserDal  _userDal;

        public UserController(IUserDal userDal)
        {
            _userDal = userDal;
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        [HttpPost,Route("Adduser")]
        public IActionResult AddUser(userInfo us)
        {
            return Ok(_userDal.AddUser(us));
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="Uname"></param>
        /// <param name="Upwd"></param>
        /// <returns></returns>
        [HttpGet, Route("Lodeuser")]
        public IActionResult Lodeuser(string Uname, int Upwd)
        {
            var a = _userDal.Lodeuser(Uname, Upwd);

            if (a != null)
            {
                var code = 1;
                var Uid = a.Uid;
                var Username = a.Uname;
                return Ok(new { code, Uid, Username });
            }
            else {
                var code = 0;
                return Ok(code);
            }
        }
        
    }
}
